package com.bokee.archerwq.lab.collection;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

class Counter {
	int count;

	@Override
	public String toString() {
		return Integer.toString(count);
	}
}

public class TestMap {

	public static void main(String[] args) {
		statistics(new HashMap<Integer, Counter>());
		statistics(new TreeMap<Integer, Counter>());
		statistics(new LinkedHashMap<Integer, Counter>());
	}

	public static void statistics(Map<Integer, Counter> map) {
		Random rand = new Random();
		long begin = System.currentTimeMillis();
		for (int i = 0; i < 10000000; i++) {
			int key = rand.nextInt(20);
			if (map.containsKey(key)) {
				((Counter) (map.get(key))).count++;
			} else {
				map.put(key, new Counter());
			}
		}
		long end = System.currentTimeMillis();
		System.out.println(map.getClass().getName() + ":" + (end - begin));
		System.out.println(map);
	}

}
